class Solution {
   public ListNode getKthFromEnd(ListNode head, int k) {
        // 获取链表的长度
        int length = 0;
        ListNode cur = head;
        while (cur != null) {
            length++;
            cur = cur.next;
        }
        // 获取链表倒数第k个节点所对应的正数第多少个节点
        int index = length - k;
        cur = head;
        while (index > 0) {
            cur = cur.next;
            index--;
        }
        return cur;
    }
}